package com.pswv2.backstage.share.keyword.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pswv2.backstage.share.keyword.service.ShareKWordService;
import com.pswv2.bub.bsc.dao.po.ShareKWord;
import com.pswv2.util.ExtraSpringHibernateTemplate;

@Service
public class ShareKWordServiceImp implements ShareKWordService {
	private static Class<?> poc = ShareKWord.class;
	@Autowired
	private ExtraSpringHibernateTemplate extraSpringHibernateTemplate;
	@Override
	public void add(ShareKWord kWord) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().save(kWord);
	}

	@Override
	public ShareKWord queryById(int id) {
		// TODO Auto-generated method stub
		return extraSpringHibernateTemplate.findFirstOneByPropEq(poc, "shareKWordId", id);
	}

	@Override
	public void updata(ShareKWord shareKWord) {
		// TODO Auto-generated method stub
		extraSpringHibernateTemplate.getHibernateTemplate().update(shareKWord);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ShareKWord> queryAll() {
		// TODO Auto-generated method stub
		return (List<ShareKWord>) extraSpringHibernateTemplate.findAll(poc);
	}

	@Override
	public ShareKWord queryByName(String name) {
		List<ShareKWord> roles=(List<ShareKWord>) extraSpringHibernateTemplate.getHibernateTemplate().find("From ShareKWord where name=? ", name);
		if(roles.size()>0){
			return  roles.get(0);
		}
		return null;
	}
}
